package com.kele.repository;

import com.kele.entity.Course;
import org.springframework.stereotype.Repository;

import java.lang.reflect.MalformedParameterizedTypeException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @Version 2019
 * @Author:kele
 * @Date:2021/5/29
 * @Content:
 * @Description：
 */
@Repository
public class CourseRepository {

    private Map<Integer, Course> courseMap;

    public CourseRepository() {
        courseMap=new HashMap<>();
        courseMap.put(1,new Course(1,"Java",Double.parseDouble("500")));
        courseMap.put(2,new Course(2,"Html",Double.parseDouble("600")));
        courseMap.put(3,new Course(3,"Mysql",Double.parseDouble("700")));
    }

    public Collection<Course> findAll(){
        return courseMap.values();
    }

    public Course findById(Integer id){
        return courseMap.get(id);
    }

    public void  saveOrUpdate(Course course){
        courseMap.put(course.getId(),course);

    }

    public void deleteById(Integer id){
        courseMap.remove(id);
    }
}
